/*  KDevelop 4.3.1
 *  HISTOGRA.cxx
 *
 *      Author : Pallab
 *      Created on: 8:15:44 PM - 2013:1:15
 *      "I have not failed, I have just found 10000 ways that won't work."
 */
#include <iostream>
#include <algorithm>
#include <vector>
#include <sstream>
#include <fstream>
#include <string>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <numeric>
#include <stack>
#include <functional>
#include <bitset>
#include <iomanip>

#include <ctime>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <climits>
#include <cstring>
#include <cstdlib>

using namespace std;


#define foR(i,frm,upto) for( int i=(frm),_i=(upto);(i) < (_i) ; ++i )
#define foD(i,frm,upto) for( int i=(frm),_i=(upto);(i) >= (_i) ; --i )
#define foit(i, x) for (typeof((x).begin()) i = (x).begin(); i != (x).end(); i++)
#define Int long long
#define pb push_back
#define SZ(X) (int)(X).size()
#define LN(X) (int)(X).length()
#define mk make_pair
#define SET( ARRAY , VALUE ) memset( ARRAY , VALUE , sizeof(ARRAY) )
#define line puts("")

inline void wait ( double seconds ) {
    double endtime = clock() + ( seconds * CLOCKS_PER_SEC );
    while ( clock() < endtime ) {
        ;
    }
}
template<class T>
    inline T fastIn() {
    register char c=0;
    register T a=0;
    bool neg=false;
    while ( c<33 ) c=getchar();
    while ( c>33 ) {
        if ( c=='-' ) {
            neg=true;
        } else {
            a= ( a*10 ) + ( c-'0' );
        }
        c=getchar();
    }
    return neg?-a:a;
}
const int MX=100005;
int numberCount;
int numbers[MX];

template<class T>
    inline T HighestOneBit ( T num ) {
    if ( num== ( T ) 0 )
        return ( T ) 0;
    T ret = 1;
    while ( num >>= 1 )
        ret <<= 1;

    return ret;
}
template<class V, class D>
        class IntervalTree {
            private:
            int size;
            V *value;
            D *delta;
            public:
            IntervalTree ( int _size ) {
                this->size=_size;
                int nodeCount = max ( 1,HighestOneBit<int> ( size ) ) <<2;
                value = new V[nodeCount];
                delta = new D[nodeCount];
            }
            ~IntervalTree() {
                delete[] value;
                delete[] delta;
            }
            inline V neutralValue() {
                return -1;
            }
            inline D neutralDelta() {
                return 0;
            }
            inline V initValue ( int index ) {
                return index;
            }
            inline V joinValue ( V left, V right ) {
                if ( left==-1 ) return right;
                if ( right==-1 ) return left;
                if ( numbers[ ( int ) left] < numbers[ ( int ) right] ) {
                    return left;
                }
                return right;
            }
            inline D joinDelta ( D was, D delta ) {
                return was ;
            }
            inline V accumulate ( V value, D delta, int length ) {
                return value ;
            }

            inline void init() {
                init ( 0,0,size-1 );
            }
            inline void init ( int root, int left, int right ) {
                if ( left==right ) {
                    value[root]=initValue ( left );
                    delta[root]=neutralDelta();
                } else {
                    int middle= ( left+right ) >>1;
                    init ( 2*root+1, left,middle );
                    init ( 2*root+2, middle+1,right );
                    value[root]=joinValue ( value[2*root+1],value[2*root+2] );
                    delta[root]=neutralDelta();
                }
            }
            inline V query ( int from, int to ) {
                return query ( 0, 0, size - 1, from, to );
            }

            inline V query ( int root, int left, int right, int from, int to ) {
                if ( left > to || right < from )
                    return neutralValue();
                if ( left >= from && right <= to )
                    return value[root];
                delta[2 * root + 1] = joinDelta ( delta[2 * root + 1], delta[root] );
                delta[2 * root + 2] = joinDelta ( delta[2 * root + 2], delta[root] );
                int middle = ( left + right ) >> 1;
                value[2 * root + 1] = accumulate ( value[2 * root + 1], delta[root], middle - left + 1 );
                value[2 * root + 2] = accumulate ( value[2 * root + 2], delta[root], right - middle );
                this->delta[root] = neutralDelta();
                return joinValue ( query ( 2 * root + 1, left, middle, from, to ), query ( 2 * root + 2, middle + 1, right, from, to ) );
            }

        };
inline void read() {
    foR ( i,0,numberCount ) {
        numbers[i]=fastIn<int>();
    }
}
inline int getMin ( int from, int to ) {
    int mn=-1;
    foR ( i,from,to+1 ) {
        if ( mn==-1 ) mn=numbers[i];
        else mn=min ( mn,numbers[i] );
    }
    return mn;
}

inline void proc() {
    IntervalTree<int,int> RMQ ( numberCount );
    RMQ.init();
    stack< pair<int,int> > STACK;
    STACK.push ( mk ( 0,numberCount-1 ) );
    Int bst=0;
    while ( STACK.empty() ==false ) {
        int left = STACK.top().first,right=STACK.top().second;
        STACK.pop();
        if ( left>right ) continue;
        int minimumIndex = RMQ.query ( left,right );
        Int tmp = ( 1LL* ( right-left+1 ) ) *numbers[minimumIndex];
        bst=max ( bst,tmp );
        STACK.push ( mk ( left,minimumIndex-1 ) );
        STACK.push ( mk ( minimumIndex+1,right ) );
    }
    cout<<bst<<"\n";
}
int main() {
    int kase = 1;
#if defined( xerxes_pc )
    freopen ( "in1", "r", stdin );
    kase = 1;
#endif
    while ( 1 ) {
        numberCount=fastIn<int>();
        if ( numberCount==0 ) break;
        read();
        proc();
    }
    return 0;
}

// kate: indent-mode cstyle; indent-width 4; replace-tabs on; 

